package com.practice.controller;

import com.practice.dto.user.ListUserParam;
import com.practice.response.ResponseL;
import com.practice.response.ResponseR;
import com.practice.service.UserService;
import com.practice.vo.user.DeleteUserParam;
import com.practice.vo.user.ListUserVO;
import com.practice.vo.user.UserBO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户相关接口控制器
 *
 * @author: kayn
 * 2024-11-01 17:15
 **/
@Slf4j
@RestController
@RequestMapping(value = "/jiojio/users")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 用户列表
     * @return 1
     */
    @RequestMapping(value = "/listUser", method = RequestMethod.POST)
    public ResponseL<ListUserVO> listUser(@RequestBody @Validated ListUserParam param) {
        return userService.listUser(param);
    }

    /**
     * 新增编辑用户
     * @return 1
     */
    @RequestMapping(value = "/saveOrUpdateUser", method = RequestMethod.POST)
    public ResponseR<String> saveOrUpdateUser(@RequestBody @Validated UserBO userBO) {
        return userService.saveOrUpdateUser(userBO);
    }

    /**
     * 删除用户
     * @return 1
     */
    @RequestMapping(value = "/deleteUser", method = RequestMethod.POST)
    public ResponseR<?> deleteUser(@RequestBody @Validated DeleteUserParam param) {
        return userService.deleteUser(param);
    }
}